//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<ProfileConsole.h>
///	@path	~/src/appear/xwin/
///	@date	2008/10/07
///	@brief	.

#pragma once

#include "xeres.h"

#include <deque>

#include "lib/math/rect.h"
#include "lib/utilities/dict.h"
#include "lib/utilities/observer.h"

#include "object/CVar.h"

#include "database/IData.h"

#include "graphics/IFont.h"
#include "graphics/IGeometry.h"
#include "graphics/canvas/CCanvas.h"
#include "graphics/canvas/CCanvasText.h"
#include "graphics/canvas/CCanvasTextBoard.h"

#include "appear/app/key_map.h"
#include "appear/app/console.h"
#include "appear/ctrl/ctrl_edit.h"

namespace xeres {

	/*!
		\class	ProfileConsole
		\brief	
	*/
	class ProfileConsole : public Console
	{
	public:

		/// \ctor
		ProfileConsole( void );

		/// \dtor
		virtual ~ProfileConsole( void );

	public:

	//@ interface

		/*!
			\brief		Initialize profile console.
		*/
		bool Initialize( RefWeak<IData> config );

		/*!
			\brief		Finalize console.
		*/
		virtual void Finalize( void );

		/*!
			\brief		Tick update call.
		*/
		virtual void Tick( Engine& engine );

		/*!
			\brief		Render console.
		*/
		virtual void Render( RenderContext& rc );

		/*!
			\brief		Process key input message.
		*/
		virtual HandleInput OnKeyInput( const KeyInput& input );

		/*!
			\brief		Process mouse input message.
		*/
		virtual HandleInput OnMouseInput( const MouseInput& input );

		/*!
			\brief		Callback when active or deactive.
		*/
		virtual void OnActive( bool is_active );

	private:

		// prepare console resources
		void PrepareConsoleResource( RefWeak<IRenderer> renderer );

		// update update focus
		void UpdateFocusItem( RefWeak<IRenderer> renderer );

		// try to switch to node
		bool SwitchToNode( const WString& path , size_t index );

	//@ data

		// status
		bool					m_actived;
		bool					m_reset;
		bool					m_spare0[2];

		std::deque<TextBoardLine>	m_lines;

		int						m_focusing;

		// console rectangle
		Rect<int>				m_rect;

		Ref<IGeometry>			m_backgroundLayer;
		Ref<IGeometry>			m_focusLayer;

		// outline canvas screen
		Ref<CCanvas>			m_canvas;
		Ref<CCanvasTextBoard>	m_board;

		// text font
		Ref<IFont>				m_textFont;
	};

} // namespace xeres
